package com.zch.user.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zch.domain.Result;
import com.zch.entity.TbSection;
import com.zch.user.service.TbSectionService;
import com.zch.user.mapper.TbSectionMapper;
import com.zch.user.vo.PageVo;
import com.zch.user.vo.TbSectionVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author xuebing
* @description 针对表【tb_section(部门维护表)】的数据库操作Service实现
* @createDate 2023-10-30 20:31:00
*/
@Service
public class TbSectionServiceImpl extends ServiceImpl<TbSectionMapper, TbSection>
    implements TbSectionService {

    @Autowired
   private TbSectionMapper tbSectionMapper;

    @Override
    public Result TbSectionList(PageVo pageVo, TbSectionVo tbSectionVo) {

        Page<TbSection> page = new Page<>(pageVo.getPageNum(), pageVo.getPageSize());

       Page<TbSection> tbSectionPage= tbSectionMapper.TbSectionList(page,tbSectionVo);

        return Result.SUCCESS(tbSectionPage);
    }


    @Override
    public Result TbSectionUpdate(TbSectionVo tbSectionVo) {

        TbSection tbSection = new TbSection();
        BeanUtils.copyProperties(tbSectionVo,tbSection);

        boolean b = updateById(tbSection);
        return b?Result.SUCCESS():Result.FAILED(502,"修改失败");
    }

    @Override
    public Result TbSectionDelete(TbSectionVo tbSectionVo) {
        TbSection tbSection = getById(tbSectionVo.getId());
        tbSection.setDeleted(1);

        TbSection tbSectionOne = new TbSection();
        BeanUtils.copyProperties(tbSection,tbSectionOne);

        boolean b = updateById(tbSectionOne);
        return b?Result.SUCCESS():Result.FAILED(502,"删除失败");
    }

    @Override
    public Result TbSectionSave(TbSectionVo tbSectionVo) {

        TbSection tbSectionOne = new TbSection();

        BeanUtils.copyProperties(tbSectionVo,tbSectionOne);
        boolean save = save(tbSectionOne);

        return save?Result.SUCCESS():Result.FAILED(502,"删除失败");
    }
}




